{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##  _*SVM with a classical RBF kernel: multiclass classifier extension*_\n",
    "\n",
    "A multiclass extension works in conjunction with an underlying binary (two class) classifier to provide multiclass classification.\n",
    "\n",
    "Currently three different multiclass extensions are supported:\n",
    "\n",
    "* OneAgainstRest\n",
    "* AllPairs\n",
    "* ErrorCorrectingCode\n",
    "\n",
    "These use different techniques to group the data with binary classification to achieve the final multiclass classification."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from qiskit.ml.datasets import wine\n",
    "from qiskit.aqua.utils import split_dataset_to_data_and_labels\n",
    "from qiskit.aqua.algorithms import SklearnSVM\n",
    "from qiskit.aqua.components.multiclass_extensions import (OneAgainstRest,\n",
    "                                                          AllPairs,\n",
    "                                                          ErrorCorrectingCode)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Here we choose the `Wine` dataset which has 3 classes."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYIAAAEICAYAAABS0fM3AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nO3dfbhcZXnv8e/PkJAY2yRIDoSEAFEqIlLgbKkHPBUBAzWVUEWM1hpfaGqrJUdbajic6i6KxtqWhlOvCkUEayvEWDGc6IlAAF9RNhCBYAMh6EnCBiIQ1JBACPf5Yz0DK5OZPbP3vM/6fa5rrpl51lqz7lk7Wfc8L+tZigjMzKy4XtTpAMzMrLOcCMzMCs6JwMys4JwIzMwKzonAzKzgnAjMzArOicBaQlJIenl6/XlJf93pmCqRdJKkzW3e56Hp+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OWF8GXtKpOIETUiw/Sc/vz20/h+zktQH4KrBvB+N8F7ALWJt7HNPq40k2+uI+sl91F6SyC8lOqgAT07HZkI7VnNy2F6Tt1gO/18J/j7VivAF4JHfcVtb623cozk8D61I8NwFH5LZ9XzrGG4D3djLO9H4QWFq2XduOJ9mPy+H0f2IzWd/PB4APpOUCPpe+w93AQLOPpaeYMDMrODcNmZkVnBOBmVnBORGYmRWcE4GZWcE5EZiZFZwTgZlZwTkRmJkV3P8Hx6EdmEAaY3IAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "feature_dim = 2  # dimension of each data point\n",
    "sample_Total, training_input, test_input, class_labels = wine(training_size=20,\n",
    "                                                              test_size=10, n=feature_dim, plot_data=True)\n",
    "\n",
    "temp = [test_input[k] for k in test_input]\n",
    "total_array = np.concatenate(temp)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now we setup the classical `SVM` algorithm and add a multiclass extension to classify the Wine data set, since it has 3 classes. We loop over the three extensions to show the result with each."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "----- Using multiclass extension: 'OneAgainstRest' -----\n",
      "\n",
      "'testing_accuracy' : 1.0\n",
      "'test_success_ratio' : 1.0\n",
      "'predicted_labels' : [0 0 1 1 1 2 2 2 2 2]\n",
      "'predicted_classes' : ['A', 'A', 'B', 'B', 'B', 'C', 'C', 'C', 'C', 'C']\n",
      "\n",
      "----- Using multiclass extension: 'AllPairs' -----\n",
      "\n",
      "'testing_accuracy' : 1.0\n",
      "'test_success_ratio' : 1.0\n",
      "'predicted_labels' : [0 0 1 1 1 2 2 2 2 2]\n",
      "'predicted_classes' : ['A', 'A', 'B', 'B', 'B', 'C', 'C', 'C', 'C', 'C']\n",
      "\n",
      "----- Using multiclass extension: 'ErrorCorrectingCode' -----\n",
      "\n",
      "'testing_accuracy' : 1.0\n",
      "'test_success_ratio' : 1.0\n",
      "'predicted_labels' : [0 0 1 1 1 2 2 2 2 2]\n",
      "'predicted_classes' : ['A', 'A', 'B', 'B', 'B', 'C', 'C', 'C', 'C', 'C']\n"
     ]
    }
   ],
   "source": [
    "extensions = [ OneAgainstRest(),\n",
    "               AllPairs(),\n",
    "               ErrorCorrectingCode(code_size=5) ]\n",
    "\n",
    "for extension in extensions:\n",
    "    result = SklearnSVM(training_input, test_input, total_array, multiclass_extension=extension).run()\n",
    "    print(\"\\n----- Using multiclass extension: '{}' -----\\n\".format(extension.__class__.__name__))\n",
    "    for k,v in result.items():\n",
    "        print(\"'{}' : {}\".format(k, v))\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
